home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / mathstud.zip / INVHILB.M < prev    next >
Text File  |  1992-09-10  |  618b  |  27 lines

  1. function [y] = invhilb(n) 
  2. %invhilb create Inverse Hilbert matrix (a badly conditioned matrix)
  3.  
  4. %       S.Halevy 7/31/92
  5. %       Copyright (c) 1992 by the MathWizards
  6.  
  7. % set up factors
  8. mv_p  = zeros(1,n);
  9. mv_p(1) = n;
  10. for ix=2:n
  11.   mv_p(ix)=((n-ix+1)*mv_p(ix-1)*(n+ix-1))/(ix-1)^2;
  12. end
  13.  
  14. % initialize matrix
  15. nv = 1:n;
  16. y = diag( (mv_p.^2) ./ (2*nv-1) );
  17.  
  18. % do it
  19. for ix = 1:n-1               % for all rows
  20.   mv_r=mv_p(ix)^2;
  21.   for jx=ix+1:n           % for elements above the diagonal
  22.     mv_r *= -((n-jx+1)*(n+jx-1))/(jx-1)^2;
  23.     y(ix,jx) = mv_r/(ix+jx-1);
  24.     y(jx,ix) = y(ix,jx);
  25.   end
  26. end
  27.